<!-- 业务信息-->
<template>
  <div>
    <el-form :model="typeForm" ref="typeForm" label-width="180px" label-position="left">
      <el-form-item
        label="权限："
        prop="quaxian"
        :disabled="typeStatus =='view'"
        :rules="rules.quaxian"
      >
        <el-checkbox
          label="新房"
          :value="houseCheck"
          :disabled="typeStatus =='view'"
          @change="(val)=> typeForm.house = val?0:-1"
        ></el-checkbox>
        <el-checkbox
          label="保险"
          :value="insuranceCheck"
          :disabled="typeStatus =='view'"
          @change="(val)=> typeForm.insurance = val?0:-1"
        ></el-checkbox>
        <el-checkbox
          label="产权"
          :value="propertyCheck"
          :disabled="typeStatus =='view'"
          @change="(val)=> typeForm.property = val?0:-1"
        ></el-checkbox>
      </el-form-item>
      <el-form-item v-if="houseCheck" label="新房分佣比例：" prop="house" :rules="rules.scale">
        <div v-if="typeStatus !='view'" style="display:flex">
          <el-input v-model.trim="typeForm.house" min="0" type="number" autocomplete="off"></el-input>
          <span style="margin-left:5px">%</span>
        </div>
        <span v-else>{{typeForm.house+'%'}}</span>
      </el-form-item>
      <el-form-item v-if="insuranceCheck" label="保险分佣比例：" prop="insurance" :rules="rules.scale">
        <div v-if="typeStatus !='view'" style="display:flex">
          <el-input v-model.trim="typeForm.insurance" min="0" type="number" autocomplete="off"></el-input>
          <span style="margin-left:5px">%</span>
        </div>
        <span v-else>{{typeForm.insurance+'%'}}</span>
      </el-form-item>
      <el-form-item v-if="propertyCheck" label="产权分佣比例：" prop="property" :rules="rules.scale">
        <div v-if="typeStatus !='view'" style="display:flex">
          <el-input v-model.trim="typeForm.property" min="0" type="number" autocomplete="off"></el-input>
          <span style="margin-left:5px">%</span>
        </div>
        <span v-else>{{typeForm.property+'%'}}</span>
      </el-form-item>
      <el-form-item label="佣金税率：" prop="taxrate" :rules="rules.scale">
        <div v-if="typeStatus !='view'" style="display:flex">
          <el-input v-model.trim="typeForm.taxrate" min="0" type="number" autocomplete="off"></el-input>
          <span style="margin-left:5px">%</span>
        </div>
        <span v-else>{{typeForm.taxrate?typeForm.taxrate+'%':''}}</span>
      </el-form-item>
      <el-form-item label="是否可使用金融产品："> 
        <el-radio-group v-if="typeStatus !='view'" v-model="typeForm.companyRepresen">
          <el-radio :label="1">是</el-radio>
          <el-radio :label="0">否</el-radio>
        </el-radio-group>
         <span v-else>{{typeForm.companyRepresen?'是':'否'}}</span>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import api from "@/api/apiPath";
import utils from "@/common/utils";
export default {
  components: {},
  props: ["typeForm", "typeStatus", "necessary"],
  computed: {
    houseCheck() {
      return this.typeForm.house != -1;
    },
    insuranceCheck() {
      return this.typeForm.insurance != -1;
    },
    propertyCheck() {
      return this.typeForm.property != -1;
    }
  },
  data() {
    return {
      rules: {
        quaxian: [
          {
            required: false,
            trigger: ["blur", "change"],
            validator: (rule, value, callback) => {
              value =
                this.houseCheck ||
                this.insuranceCheck ||
                this.propertyCheck ||
                "";
              if (!value && this.necessary) {
                callback(new Error(`请选择权限`));
              }
              callback();
            }
          }
        ],
        scale: [
          {
            required: false,
            trigger: ["blur", "change"],
            validator: (rule, value, callback) => {
              let ruleMsg = {
                taxrate: "佣金税率",
                house: "新房分佣比例",
                insurance: "保险分佣比例",
                property: "产权分佣比例"
              }[rule.field];
              if (!value && value !== 0 && this.necessary) {
                callback(new Error(`请输入${ruleMsg}`));
              }
              if (value < 0) {
                callback(new Error(`请输入正确格式的${ruleMsg}`));
              } else {
                callback();
              }
            }
          }
        ]
      }
    };
  },
  methods: {
    veri() {
      let _this = this;
      return new Promise((resolve, reject) => {
        _this.$refs.typeForm.validate(valid => {
          resolve(valid);
        });
      });
    }
  },
  created() {},
  destroyed() {},
  filters: {}
};
</script>


